﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework;
using CNVP.Framework.Utils;
using CNVP.JShop.UI;

namespace CNVP.JShop.Web.Admin
{
    public partial class AdminUpdatePwd : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 0)) return;//判断页面权限
        }

        protected void btUp_Click(object sender, EventArgs e)
        {
            try
            {
                string OldPwd = this.txtOldPwd.Text.Trim();
                string UserPass1 = txtPwd1.Text.Trim();
                string UserPass2 = txtPwd2.Text.Trim();
                if (string.IsNullOrEmpty(OldPwd))
                {
                    BasePage.MessageBoxGoHistory("旧密码不能为空！");
                }
                if (string.IsNullOrEmpty(UserPass1))
                {
                    BasePage.MessageBoxGoHistory("新密码不能为空！");
                }
                if (string.IsNullOrEmpty(UserPass2))
                {
                    BasePage.MessageBoxGoHistory("确认密码不能为空！");
                }
                if (UserPass2 != UserPass1)
                {
                    BasePage.MessageBoxGoHistory("新密码和确认密码不相等！");
                }

                if (new BLL.CNVP_Admin().IsOldPwd(EncryptUtils.MD5(OldPwd), CookieString) > 0)
                {
                    new BLL.CNVP_Admin().UpdatePwd(EncryptUtils.MD5(UserPass1), CookieString);
                    BasePage.MessageBoxGoHistory("密码修改成功！");
                }
                else
                {
                    BasePage.MessageBoxGoHistory("旧密码不存在！");
                }
            }
            catch
            {
                BasePage.MessageBoxGoHistory("悲剧，出错了！");
            }

        }
    }
}
